package io.renren.modules.student.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.utils.SnowFlake;
import io.renren.modules.student.service.StuExploreService;
import io.renren.modules.sys.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stu/explore")
public class StuExploreController extends AbstractController {
    @Autowired
    private StuExploreService stuExploreService;
  /*
  获得课程列表
   */
    @GetMapping("/list")
    public R List(@RequestParam Map<String, Object> params){

        PageUtils result = stuExploreService.queryList(params);
        return R.ok("succese").put("page",result);
    }
    /*
    获得最新课程
     */
    @GetMapping("/newData")
    public R newData(){
       Map<String, Object> result = stuExploreService.queryNewData();
        return R.ok().put("data",result);
    }

    /*
    得到每个课程的老师信息
     */
    @GetMapping("/teacherInfo")
    public R teacherInfo(@RequestParam Map<String,Object> param){
        Map<String, String> result = stuExploreService.queryTeacherInfo(param);
        return R.ok().put("data",result);
    }

    /*
    获得每个课程的所有章节列表数据
     */
    @GetMapping("/chapter")
    public R chapter(@RequestParam Map<String, Object> param){
        List<Map<String, String>> result = stuExploreService.queryChapter(param);
        return R.ok().put("data",result);
    }

    /*
    * 获得该章节数据
    * */
    @GetMapping("/chapterData")
    public R chapterData(@RequestParam Map<String, Object> param){
        Map<String, String> result = stuExploreService.queryChapterData(param);
        return R.ok().put("data",result);
    }
    /*
     获得章节编码内容
    */
    @GetMapping("/chapterContent")
    public R chapterContent(@RequestParam String chapterId){
        List<Map<String, Object>> result = stuExploreService.queryContent(chapterId);
        return R.ok().put("data",result);
    }
    /*
    获得每个课程介绍
     */
    @GetMapping("/courseIntro")
    public R courseIntro(@RequestParam Map<String, Object> param){
        param.put("userId",getUserId()+"");
        Map<String, String> result = stuExploreService.queryCourseIntro(param);
        return R.ok().put("data",result);
    }
    /*
    加入课程
     */
    @PostMapping("/addCourse")
    public R addCourse(@RequestBody Map<String, Object> param) {
        param.put("userId",getUserId()+"");
        stuExploreService.insertCourse(param);
        return R.ok();
    }

}
